package org.dfl.plugin.editor.contributionitems;

import org.dfl.plugin.editor.actions.ResumeOnceStepDisabledTokensAction;
import org.dfl.plugin.editor.model.DflDiagram;
import org.eclipse.jface.action.IAction;
import org.eclipse.swt.widgets.ToolItem;

/**
 * contribution item for ResumeOneStepDisabledTokensAction action
 * @author Piotr Wlodarczyk
 *
 */
public class ResumeOneStepDisabledTokensActionContributionItem extends FlowRunnerActionContributionItem {
	private IAction action;
	
	@Override
	public void setDiagram(DflDiagram diagram) {
		action = new ResumeOnceStepDisabledTokensAction(null,diagram);
		super.setDiagram(diagram);
	}

	@Override
	protected void itemSelected() {
		if(action.isEnabled()){
			action.run();
		}
	}

	@Override
	protected void updateItem(ToolItem item) {
		if(item!=null){
			if(diagram==null){
				setAction(item,false);
			}else if(action.isEnabled()){
				setAction(item,true);
			}else{
				setAction(item,false);
			}
		}	
	}
	
	private void setAction(ToolItem item,boolean enabled){
		item.setImage(action.getImageDescriptor().createImage());
		item.setToolTipText(action.getToolTipText());
		item.setEnabled(enabled);
	}
}
